<%--
  Created by IntelliJ IDEA.
  User: 猽
  Date: 2020/12/26
  Time: 22:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/layui/css/layui.css">
</head>
<body>
<form class="layui-form layui-form-pane">
    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-inline">
            <input type="text" readonly class="layui-input" value="${user.realname}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-inline">
            <input type="text" readonly class="layui-input" value="${user.username}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-inline">
            <input type="text" name="password" autocomplete="off" class="layui-input" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">新密码</label>
        <div class="layui-inline">
            <input type="text"  autocomplete="off" class="layui-input"  name="newPassword">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">确认密码</label>
        <div class="layui-inline">
            <input type="text"  autocomplete="off" class="layui-input"  name="confirmPassword">
        </div>
    </div>
    <div class="layui-form-item" style="margin-top: 30px">
        <button style="margin-left: 50px;margin-right: 50px" class="layui-btn" type="button" lay-submit lay-filter="subBtnFilter">确认</button>
        <button class="layui-btn layui-btn-primary" type="reset">重置</button>
    </div>
</form>

<script src="${pageContext.request.contextPath}/resources/layui/layui.js"></script>
<script>
    layui.use(['form','layer','jquery'],function () {
        let form = layui.form;
        let layer = layui.layer;
        let $ = layui.jquery;
        let cxt = "${pageContext.request.contextPath}";
        //表单提交
        form.on("submit(subBtnFilter)",function (d) {
            let formData = d.field;
            let newPassword = formData.newPassword;//新密码
            let confirmPassword = formData.confirmPassword;//确认密码
            if (newPassword != confirmPassword){
                layer.msg("两次密码不一致!");
                return  false;
            }
            $.post(cxt+"/user.do?service=updatePassword",formData,function (rs) {
                layer.msg(rs.msg);
                if (rs.code != 200){
                    return false;
                }
                layer.alert("密码修改成功,请重新登录",function (index) {
                    window.parent.location.href = cxt +"/index.jsp";
                    return false;
                });
                //规避用户不点击确认,直接关闭弹层 使用定时任务自动跳转到登录页面
                setTimeout(function () {
                    window.parent.location.href = cxt +"/index.jsp";
                },2000)

            });
            return false;
        })
    })
</script>
</body>
</html>

